package com.zhq.user.dao;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.zhq.Interface.user.dao.IUserDao;
import com.zhq.user.entity.User;

/**
 * 
 * <p></p>
 * @author zhanghanqing 2013-11-15 下午12:33:24
 * @version V1.0   
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify by user: {修改人} 2013-11-15
 * @modify by reason:{方法名}:{原因}
 */
public class UserDao extends HibernateDaoSupport implements IUserDao,Serializable{
	
//	@Autowired
//	public void setSessionFactorySF(SessionFactory sessionFactory) {
//		super.setSessionFactory(sessionFactory);
//	}

	/**
     * 序列化ID
     */
    private static final long serialVersionUID = -2378947254992259335L;

	public void saveUser(User user) {
		getHibernateTemplate().save(user);
		
	}
	
	public User fetchUserById(int id) {
		return (User)getHibernateTemplate().get(User.class, id);
		
	}

	@SuppressWarnings("unchecked")
    public List<User> fetchUsers() {
	    List<User> users = new ArrayList<User>();
	    users = getHibernateTemplate().loadAll(User.class);
	    return users;
    }

	public void deleteUser(int id) {
	    getHibernateTemplate().delete((User)getHibernateTemplate().get(User.class, id));	    
    }

	public void updateUser(User user) {
	    getHibernateTemplate().update(user);	    
    }
}
